/*    */ package handling.cashshop.handler;
/*    */ 
/*    */

import client.MapleCharacter;
import client.MapleCharacterUtil;
import client.MapleClient;
import client.inventory.Item;
import constants.ItemConstants;
import server.MapleInventoryManipulator;
import server.cashshop.CashItemFactory;
import server.cashshop.CashItemInfo;
import tools.DateUtil;
import tools.Triple;
import tools.data.input.LittleEndianAccessor;
import tools.packet.MTSCSPacket;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */

/*    */
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CouponCodeHandler
/*    */ {
/*    */   public static void handlePacket(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 30 */     String toPlayer = slea.readMapleAsciiString();
/* 31 */     if (toPlayer.length() > 0) {
/* 32 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示(22));
/* 33 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/*    */       return;
/*    */     } 
/* 36 */     String code = slea.readMapleAsciiString();
/* 37 */     if (code.length() <= 0) {
/* 38 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/*    */       return;
/*    */     } 
/* 41 */     Triple<Boolean, Integer, Integer> info = null;
/*    */     try {
/* 43 */       info = MapleCharacterUtil.getNXCodeInfo(code);
/* 44 */     } catch (SQLException e) {
/* 45 */       System.out.print("错误 getNXCodeInfo" + e);
/*    */     } 
/* 47 */     if (info != null && ((Boolean)info.left).booleanValue()) {
/* 48 */       CashItemInfo itez; byte slot; int type = ((Integer)info.mid).intValue(), item = ((Integer)info.right).intValue();
/*    */       try {
/* 50 */         MapleCharacterUtil.setNXCodeUsed(chr.getName(), code);
/* 51 */       } catch (SQLException e) {
/* 52 */         System.out.print("错误 setNXCodeUsed" + e);
/* 53 */         c.announce(MTSCSPacket.INSTANCE.商城错误提示(0));
/*    */ 
/*    */ 
/*    */ 
/*    */         
/*    */         return;
/*    */       } 
/*    */ 
/*    */ 
/*    */ 
/*    */       
/* 64 */       Map<Integer, Item> itemz = new HashMap<>();
/* 65 */       int maplePoints = 0, mesos = 0;
/* 66 */       switch (type) {
/*    */         case 1:
/*    */         case 2:
/* 69 */           c.getPlayer().modifyCSPoints(type, item, false);
/* 70 */           maplePoints = item;
/*    */           break;
/*    */         case 3:
/* 73 */           itez = CashItemFactory.getInstance().getItem(item);
/* 74 */           if (itez == null) {
/* 75 */             c.announce(MTSCSPacket.INSTANCE.商城错误提示(0));
/*    */             return;
/*    */           } 
/* 78 */           slot = MapleInventoryManipulator.addId(c, itez.getItemId(), (short)1, "", "商城道具卡兑换 时间: " + DateUtil.getCurrentDate());
/* 79 */           if (slot <= -1) {
/* 80 */             c.announce(MTSCSPacket.INSTANCE.商城错误提示(0));
/*    */             return;
/*    */           } 
/* 83 */           itemz.put(Integer.valueOf(item), chr.getInventory(ItemConstants.getInventoryType(item)).getItem((short)slot));
/*    */           break;
/*    */         
/*    */         case 4:
/* 87 */           chr.gainMeso(item, false);
/* 88 */           mesos = item;
/*    */           break;
/*    */       } 
/* 91 */       c.announce(MTSCSPacket.INSTANCE.showCouponRedeemedItem(itemz, mesos, maplePoints, c));
/* 92 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/*    */     } else {
/* 94 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示((info == null) ? 14 : 16));
/*    */     } 
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\handling\cashshop\handler\CouponCodeHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */